let dlObj=document.querySelector('header .member > div')
dlObj.onclick=function(){
    let logObj=document.querySelector('section.login')
    logObj.style.visibility='visible'
}
let gbObj=document.querySelector('section.login i.icon-close')
gbObj.onclick=function(){
    let logObj=document.querySelector('section.login')
    logObj.style.visibility=' hidden'
}

let loginBlueBox = document.querySelector('section.login .menu')
loginBlueBox.onmousedown = function(evt) 
{
    let oldE = evt || window.event
    document.onmousemove = function(evt) 
    {
        let e = evt || window.event
        let left = e.clientX - oldE.offsetX
        let top = e.clientY - oldE.offsetY
        if (left<0) left = 0
        if (top<0) top = 0
        let loginDialog = document.querySelector('section.login .item')
        let maxLeft = (window.innerWidth || document.documentElement.clientWidth) - loginDialog.offsetWidth
        let maxTop = (window.innerHeight || document.documentElement.clientHeight) - loginDialog.offsetHeight
        if (left > maxLeft) left = maxLeft
        if (top > maxTop) top = maxTop
        loginDialog.style.position = 'absolute'
        loginDialog.style.left = left + 'px'
        loginDialog.style.top = top + 'px'
    }
    document.onmouseup = function() {
        document.onmousemove = null
    }
}

let num=5
let yanzmObj=document.querySelector('section.login .captcha')
yanzmObj.onclick=function(){
    let captchaObj = document.querySelector('section.captcha')
    captchaObj.style.visibility = 'visible'
    document.querySelector('section.captcha i.icon-close').onclick = function() {
        captchaObj.style.visibility = 'hidden'
    }
    let dragBtn = captchaObj.querySelector('.drag .btn')
    dragBtn.onmousedown = function() {
        document.onmousemove = function(evt) {
            let e = evt || window.event
            let left = e.clientX - (captchaObj.offsetLeft - captchaObj.offsetWidth/2) - dragBtn.offsetWidth
            dragBtn.style.left = left + 'px'
            captchaObj.querySelector('.check img:nth-of-type(2)').style.left = left + 'px'
        }
        document.onmouseup = function() {
            document.onmousemove = null
            let value = parseInt(dragBtn.style.left)
            if (value >= 260 && value<=265)
            {
                captchaObj.style.visibility = 'hidden'
                loginCaptchaBtn.innerText = num+'秒后重发'
                loginCaptchaBtn.disabled =  true
                t = setInterval(function() {
                    if (num<=1) {
                        clearInterval(t)
                        loginCaptchaBtn.innerText = '重新发送'
                        num = 5
                        loginCaptchaBtn.disabled =  false
                        return
                    }
                    num--
                    loginCaptchaBtn.innerText = num+'秒后重发'
                }, 1000)

            }
            dragBtn.style.left =  '0px'
            captchaObj.querySelector('.check img:nth-of-type(2)').style.left =  '0px'
        }
    }
    return
}

var loginSubmitBtn = document.querySelector('section.login .submit')
loginSubmitBtn.onclick = function() 
{
    var isOk = 0
    var mobileObj = document.querySelector('.mobile')
    if (mobileObj.value == '' || mobileObj.value.length != 11 || !Number(mobileObj.value))
    {
        document.querySelector('section.login .form > p:nth-of-type(3)').innerText = '手机格式有误📱'
    } else {
        isOk++
        document.querySelector('section.login .form > p:nth-of-type(3)').innerText = ''
    }
    var passwordObj = document.querySelector('.password')
    if (passwordObj.value == '' || passwordObj.value.length != 4 || !Number(passwordObj.value))
    {
        document.querySelector('section.login .form > p:nth-of-type(4)').innerText = '验证码只能是4位村数字🔢'
    } else {
        isOk++
        document.querySelector('section.login .form > p:nth-of-type(4)').innerText = ''
    }
    if (isOk==2) {
        alert('登录成功')
    }
}


